package main

import (
	"fmt"
	"github.com/PuerkitoBio/goquery"
	"net/http"
)

func getDocument(url string) (doc *goquery.Document, err error) {
	resp, err := http.Get(url)
	if err != nil {
		return nil, err
	}

	doc, err = goquery.NewDocumentFromReader(resp.Body)
	if err != nil {
		return nil, err
	}

	return doc, nil
}

func xiaomiMIJIA() {
	index := "http://bbs.xiaomi.cn/f-363"
	doc, er := getDocument(index)
	if er != nil {
		panic(er)
	}
	containPlateDom := doc.Find(".main .contain_plate")
	containRightDom := containPlateDom.Find(".contain_right")
	themelistconDom := containRightDom.Find("ul.themelistcon")
	themelistconDom.Children().Each(func(i int, li *goquery.Selection) {
		themeListConDom := li.Find(".theme_list_con")
		titleDom := themeListConDom.Find(".title")
		titleNameDom := titleDom.Find(".title_name")
		href, exists := titleNameDom.Attr("href")
		if !exists {
			return
		}
		title := titleNameDom.Text()
		fmt.Println("link url: ", href, title, )
	})
}

func QianjiaSmarthome() {
	index := "http://smarthome.qianjia.com/"
	fmt.Println(index)
}

func main() {
	type Seo struct {
		Title string
		Keywords string
		Description string
	}
	id := "999"
	data := map[string]interface{}{
		Seo: id, // error?
	}
	fmt.Println(data)
}
